package com.coolgor.airvow.Util;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;


public class DataTreeNode {
	private boolean isRoot;
	private int numOfLeaf ;
	private int level ;
	private String nodeID ;
	private Object object ;
	private Map<Object, Object> content ;
	private Vector<DataTreeNode> children ;
	
	public DataTreeNode () {
		this.numOfLeaf = 0 ;
		this.nodeID = "";
		content = new HashMap<Object, Object>();
		children = new Vector<DataTreeNode>();
	}
	
	public DataTreeNode (String nodeID) {
		this.numOfLeaf = 0 ;
		this.nodeID = nodeID;
		content = new HashMap<Object, Object>();
		children = new Vector<DataTreeNode>();
	}
	
	
	public void setRoot(boolean isRoot) {this.isRoot = isRoot;}

	public void setNumOfLeaf(int i){ this.numOfLeaf = i ; }
	public int getNumOfLeaf(){ return this.numOfLeaf ; }
	
	public void setNodeID(String nodeID){ this.nodeID = nodeID ; }
	public String getNodeID(){ return this.nodeID ; }
	
	public Object getObject() {	return object;	}
	public void setObject(Object object) {	this.object = object; }	
	
	public Map<Object, Object> getContent() {	return content;	}
	public void setContent(Map<Object, Object> content) {	this.content = content;	}

	public Vector<DataTreeNode> getChildren() {	return children;}
	public void setChildren(Vector<DataTreeNode> children) {	this.children = children;}
	
	public boolean isLeaf(){
		if ( 0 == numOfLeaf) return true ;
		else return false ;			
	}
	
	public boolean isRoot(){
		return this.isRoot ;
	}
	
	public void addChild(DataTreeNode dataTreeNode){
		this.children.add(dataTreeNode);
		this.numOfLeaf++;
	}
	
	public void addChild(int i, DataTreeNode dataTreeNode){
		this.children.add(i,dataTreeNode);
		this.numOfLeaf++;
	}
	
	public boolean delChild(int i){
		if (i>this.numOfLeaf ) return false;
		this.children.remove(i);
		return true;
	}

	public boolean replaceChild(int i, DataTreeNode dataTreeNode){
		if (i>this.numOfLeaf ) return false;
		this.addChild(i, dataTreeNode);
		this.delChild(i+1);
		return true;
	}
	
	public DataTreeNode getChild(int i){
		if (i>this.numOfLeaf ) return null;
		return (DataTreeNode) this.children.get(i);
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}	
	
}